package com.stlm2.dems.entity.base;

import com.stlm2.dems.entity.User;
import com.stlm2.dems.user.entity.Sex;
import com.stlm2.dems.user.entity.UserLevel;
import com.stlm2.dems.user.entity.UserState;
import com.stlm2.dems.user.entity.UserType;

import java.io.Serializable;
import java.util.Date;

/**
 * Created by apple on 2017/5/21.
 */
public class BaseUser implements Serializable{
    private int hashCode = Integer.MIN_VALUE;
    private Integer id;
    private String name;
    private String realName;
    private String avotorr;
    private Date createTime;
    private String userKey;
    private  String password;
    private UserState userState;
    private UserType userType;
    private String identity;
    private String QQ;
    private String weixin;
    private String email;
    private Sex sex;
    private String phone;
    private UserLevel userLevel;
    private String userUpper;
    private String wxOpenId;
    private String openId;
    private Date birthday;
    private Integer companyCode;


    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    public String getWxOpenId() {
        return wxOpenId;
    }

    public void setWxOpenId(String wxOpenId) {
        this.wxOpenId = wxOpenId;
    }

    public String getOpenId() {
        return openId;
    }

    public void setOpenId(String openId) {
        this.openId = openId;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getRealName() {
        return realName;
    }
    public void setRealName(String realName) {
        this.realName = realName;
    }

    public String getAvotorr() {
        return avotorr;
    }

    public void setAvotorr(String avotorr) {
        this.avotorr = avotorr;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public String getUserKey() {
        return userKey;
    }

    public void setUserKey(String userKey) {
        this.userKey = userKey;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public UserState getUserState() {
        return userState;
    }

    public void setUserState(UserState userState) {
        this.userState = userState;
    }

    public UserType getUserType() {
        return userType;
    }

    public void setUserType(UserType userType) {
        this.userType = userType;
    }

    public String getIdentity() {
        return identity;
    }

    public void setIdentity(String identity) {
        this.identity = identity;
    }

    public String getQQ() {
        return QQ;
    }

    public void setQQ(String QQ) {
        this.QQ = QQ;
    }

    public String getWeixin() {
        return weixin;
    }

    public void setWeixin(String weixin) {
        this.weixin = weixin;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public Sex getSex() {
        return sex;
    }

    public void setSex(Sex sex) {
        this.sex = sex;
    }

    public UserLevel getUserLevel() {
        return userLevel;
    }

    public void setUserLevel(UserLevel userLevel) {
        this.userLevel = userLevel;
    }

    public String getUserUpper() {
        return userUpper;
    }

    public void setUserUpper(String userUpper) {
        this.userUpper = userUpper;
    }

    public Integer getCompanyCode() {
        return companyCode;
    }

    public void setCompanyCode(Integer companyCode) {
        this.companyCode = companyCode;
    }

    // ----------------重写方法-------------------------
    @Override
    public int hashCode() {
        if (Integer.MIN_VALUE == this.hashCode) {
            if (this.getId() == null)
                return super.hashCode();
            else {
                String hashStr = this.getClass().getName() + ":"
                        + this.getId().hashCode();
                this.hashCode = hashStr.hashCode();
            }
        }

        return this.hashCode;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }

        if (!(obj instanceof User)) {
            return false;
        } else {
            User user = (User) obj;
            if (this.getId() == null || user.getId() == null)
                return false;
            else
                return (this.getId().equals(user.getId()));
        }
    }

    @Override
    public String toString() {
        return super.toString();
    }


    /**
     * 映射：用户状态
     */
    public Integer getUserStateValue() {
        // return getFirstWord().getIntValue();
        return (userState != null) ? userState.getIntValue() : null;
    }

    public void setUserStateValue(Integer value) {
        if (value != null)
            this.userState = UserState.getByIntValue(value);
    }

    /**
     * 映射：用户类型
     */
    public Integer getUserTypeValue() {
        // return getFirstWord().getIntValue();
        return (userType != null) ? userType.getIntValue() : null;
    }

    public void setUserTypeValue(Integer value) {
        if (value != null)
            this.userType = UserType.getByIntValue(value);
    }

    /**
     * 映射：用户性别
     */
    public Integer getSexValue() {
        return (sex != null) ? sex.getIntValue() : null;
    }

    public void setSexValue(Integer value) {
        if (value != null)
            this.sex = Sex.getByIntValue(value);
    }

    /**
     * 映射：用户消费商级别
     */
    public Integer getUserLevelValue() {
        return (userLevel != null) ? userLevel.getIntValue() : null;
    }

    public void setUserLevelValue(Integer value) {
        if (value != null)
            this.userLevel = UserLevel.getByIntValue(value);
    }


}
